home *** CD-ROM | disk | FTP | other *** search
/ DOpus Plus / DOpus Plus.iso / Tutorial / C Guide / Simple_Module2 / DetachWindow / ModuleEntry.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-18  |  3.2 KB  |  104 lines

  1. /*******************************************************************
  2.  
  3.    ModuleEntry.c
  4.  
  5.    Since we want now that DOpus does start our module on its startup,
  6.     we need to modify one flag (MODULE_FLAGS). This would be to do in
  7.     the includes/Project.h, but it's also possible here.
  8.  
  9. *********************************************************************/
  10.  
  11. #define PARENT
  12. #include "/includes/Project.h"
  13.  
  14.  
  15. ModuleInfo module_info =
  16. {
  17.     MODULE_VER_NUMBER,
  18.     MODULE_NAME,
  19.     MODULE_CATALOG,
  20.     MODULE_FLAGS | MODULEF_CALL_STARTUP, // Here we add the needed flag
  21.     MODULE_FUNC_COUNT,
  22.  
  23.     { FUNC0_ID, COMMAND_0, FUNC0_DESCRIPTION, FUNC0_FLAGS, FUNC0_TEMPLATE }
  24. };
  25.  
  26. // now you must modify some lines, if your module should have more than
  27. // one command buildin...
  28. // For example we make here at all 3 commands. The 3. command itself is a
  29. // hidden command (is not shown in the commandlist...)
  30.  
  31. #if MODULE_FUNC_COUNT-1
  32.  
  33. ModuleFunction module_func[MODULE_FUNC_COUNT-1] =
  34.     { FUNC1_ID, COMMAND_1, FUNC1_DESCRIPTION, FUNC1_FLAGS, FUNC1_TEMPLATE },
  35.     { FUNC2_ID, COMMAND_2, FUNC2_DESCRIPTION, FUNC2_FLAGS, FUNC2_TEMPLATE }
  36. };
  37.  
  38. #endif
  39.  
  40.  
  41. // If you are a really nice programmer, you should provide the version
  42. // string with some extra \0 's...
  43.  
  44. static char version[] = "\0$VER: " VERSION_STRING " " __AMIGADATE__ "\0";
  45.  
  46. /********************************************************************/
  47. // Now we are ready to enter our program code...
  48.  
  49. int __asm __saveds L_Module_Entry( register __a0 char *args,              
  50.                                    register __a1 struct Screen *screen,   
  51.                                    register __a2 IPCData *ipc,
  52.                                    register __a3 IPCData *main_ipc,
  53.                                    register __d0 ULONG mod_id,
  54.                                    register __d1 EXT_FUNC(func_callback) )
  55. {  
  56.      // now we can (should) get an special value for mod_id
  57.      // as action we do here launch one of our commands (the requester)
  58.      // it will be done with EXT_FUNC() as ARexx command
  59.      // since it will be launched async, we have already one chance
  60.      // to detach an own process...
  61.      
  62.      // NOTE: If you use the MODULEF_STARTUP flag you'll get in some
  63.      // cases no valid screenpointer !! (not mentioned in the SDK)
  64.      
  65.      // at first we need a structure to call the func_callback()
  66.      
  67.      struct command_packet cp;
  68.                             
  69.     switch( mod_id )
  70.       {
  71.           case FUNC0_ID :  ExampleRequest( args, screen, ipc );
  72.                            break;
  73.  
  74.           case FUNC1_ID :  OwnWindow( args, screen );
  75.                            break;
  76.  
  77.           case FUNC2_ID :  HiddenCommand( args, ipc, main_ipc );
  78.                            break;
  79.                                     
  80.              case FUNCID_STARTUP:
  81.                               
  82.                                     // now fill the command_packet
  83.                                     cp.command = "command Beep"; //ExampleRequest Called on Startup";
  84.                                     // refer also the ARexx description of DOpus
  85.                                     
  86.                                     cp.flags = COMMANDF_RESULT;
  87.                                     cp.result = NULL;                                    
  88.                                     
  89.                                     // and do the command
  90.                                     
  91.                                     func_callback( EXTCMD_SEND_COMMAND, IPCDATA(ipc), &cp );
  92.                                     
  93.                                     if( cp.result )
  94.                                          FreeVec( cp.result );
  95.                                     
  96.                                     break;
  97.       }
  98.  
  99.     return 1;
  100. }
  101.  
  102.  
  103.